/*==============================================================================
 Copyright (c) 2012-2014 Qualcomm Connected Experiences, Inc.
 All Rights Reserved.
 ==============================================================================*/

package com.qualcomm.vuforia.samples.VuforiaSamples.ui.ActivityList;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;

import com.qualcomm.vuforia.samples.VuforiaSamples.R;


public class AboutScreen extends Activity implements OnClickListener
{
    private static final String LOGTAG = "AboutScreen";
    
    private WebView mAboutWebText;
    private Button mStartButton;
    private TextView mAboutTextTitle;
    private String mClassToLaunch;
    private String mClassToLaunchPackage;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Pone la pantalla completa sin titulo
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
      
        setContentView(R.layout.about_screen);
        mClassToLaunchPackage = getPackageName();
        mClassToLaunch = mClassToLaunchPackage + "."+ "app.ImageTargets.ImageTargets";

        mAboutWebText = (WebView) findViewById(R.id.about_html_text);
        //Genera un archivo aboutText para ser seteado al WebView
        String aboutText = "";
        try
        {
            InputStream is = getAssets().open("ImageTargets/IT_about.html");
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line;
            
            while ((line = reader.readLine()) != null)
            {
                aboutText += line;
            }
        } catch (IOException e)
        {
            Log.e(LOGTAG, "About html loading failed");
        }
        //Agrega el html al WebView
        mAboutWebText.loadData(aboutText, "text/html", "UTF-8");
        mStartButton = (Button) findViewById(R.id.button_start);
        //Lanza el evento onClick
        mStartButton.setOnClickListener(this);
        //Agrega el titulo 
        mAboutTextTitle = (TextView) findViewById(R.id.about_text_title);
        mAboutTextTitle.setText("Image Targets Ikaro");
        
    }
    
    
    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.button_start:
            	  Intent i = new Intent();
            	  //Se redirige a la activity que se encuentra en la ImageTarget
            	  //mClassToLaunchPackage:com.qualcomm.vuforia.samples.VuforiaSamples
            	  //mClassToLaunch:app.ImageTargets.ImageTargets
                  i.setClassName(mClassToLaunchPackage, mClassToLaunch);
                  startActivity(i);
                break;
        }
    }
}
